package com.heatingcharge.controller.base;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.ChargeDiscountDTO;
import com.heatingcharge.entity.base.ChargeDiscount;
import com.heatingcharge.param.ChargeDiscountParam;
import com.heatingcharge.service.base.IChargeDiscountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 预缴优惠表 前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-10-25
 */
@RestController
@RequestMapping("/charge-discount")
public class ChargeDiscountController {
    @Autowired
    IChargeDiscountService chargeDiscountService;

    @GetMapping
    public R getChargeDiscount(ChargeDiscountDTO chargeDiscountDTO){
//        QueryWrapper<ChargeDiscount> queryWrapper=new QueryWrapper();
//        if (chargeDiscountDTO.getHeatYearId()!=null&chargeDiscountDTO.getHeatYearId()!=0) {
//            queryWrapper.eq("heat_year_id", chargeDiscountDTO.getHeatYearId());
//        }
        return R.ok(chargeDiscountService.getChargeDiscounts(chargeDiscountDTO));
    }

    @PostMapping
    public R save(@RequestBody ChargeDiscountParam chargeDiscountParam){
        if (chargeDiscountService.save(chargeDiscountParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @PutMapping
    public R update(@RequestBody ChargeDiscountParam chargeDiscountParam){
        if (chargeDiscountService.update(chargeDiscountParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id){
        if (chargeDiscountService.delete(id)>0){
            return R.ok();
        }
        return R.error();
    }
}

